package thead;

public class Demo13 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            while(true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        System.out.println(t.getState());// 此时是NEW 当前线程只是创建了还未运行
        t.start();
        System.out.println(t.getState());// RUNNABLE就绪状态
        for (int i = 0; i < 5; i++) {
            System.out.println(t.getState());// 此处是 TIMED_WAITING 代表是sleep这种定时造成的堵塞
            Thread.sleep(1000);
        }
        t.join();
        // 在检查执行结束之后再获取线程的状态,此时就是TERMINATED 状态
        System.out.println(t.getState());
    }
}
